//
//  HSatisDetailViewController.m
//  NursingManages
//
//  Created by Zhen Huang on 17/6/22.
//  Copyright © 2017年 huangzhen. All rights reserved.
//

#import "HSatisDetailViewController.h"
#import "InitDbTable.h"
#import "HSatisDetailTableViewCell.h"
#import "SizeToFit.h"
#import "BigModel.h"
#import "MPickerSelectionView.h"
#import "HQCDepartViewController.h"
#import "Model_Hr_Satisfaction.h"
#import "HSatisSave.h"
#import "UserDefault.h"
#import "HNurseAssessUnloadViewController.h"
#import "HNurseAssessRecordViewController.h"
#import "HQPickerView.h"
@interface HSatisDetailViewController ()

<UITableViewDelegate,
UITableViewDataSource,
UITextViewDelegate,
UITextFieldDelegate,MPickerSelectionViewProtocol,HQPickerViewDelegate>
@property (nonatomic ,strong) UIDatePicker *datePicker;
@property (nonatomic ,strong) MPickerSelectionView *pickerSelectionView;
@property (nonatomic ,copy) NSString *Type_id;
@property (nonatomic ,strong) NSMutableArray *dataArray;
@property (nonatomic ,strong) NSMutableArray *titleArray;
@property (nonatomic ,strong) NSMutableArray *DetailArray;
@property (nonatomic ,strong) NSMutableArray *itemArray;
@property (nonatomic ,strong) UITableView *myTableView;
@property (nonatomic ,assign) NSInteger height;
@property (nonatomic ,assign) NSInteger HeadViewHeight;
@property (nonatomic ,assign) NSInteger indexPatch;
@property (nonatomic ,assign) NSInteger indexRow;
@property (nonatomic ,strong) Model_Hr_SatType *model;
@property (nonatomic ,strong) NSMutableArray *headArray;
@property (nonatomic ,strong) UIButton *dateTimeButton;
@property (nonatomic ,strong) UILabel *dateTimeLabel;
@property (nonatomic ,strong) UIButton *deptButton;
@property (nonatomic ,strong) NSMutableArray *saveArray;
@property (nonatomic ,strong) Model_Hr_Satisfaction *satis_Model;
@property (nonatomic ,strong) NSMutableArray *HSatisDetailArray;
@property (nonatomic ,strong) NSDictionary *paramDic;
@property (nonatomic ,assign) NSInteger dateFlag;
@property (nonatomic ,assign) NSInteger indexSection;
@property (nonatomic ,assign) CGFloat sectionHeight;
@property (nonatomic ,assign) NSInteger chooseSection;
@property (nonatomic ,strong) UIView *headView;

@property (nonatomic ,strong)NSMutableArray *heightArray;


@end

@implementation HSatisDetailViewController

- (instancetype)initWithTypeID:(NSString *)Type_id
                         param:(NSDictionary *)paramDic
{
    if (self) {
        self.Type_id = Type_id;
        self.dataArray = [NSMutableArray new];
        self.titleArray = [NSMutableArray new];
        self.DetailArray = [NSMutableArray new];
        self.itemArray = [NSMutableArray new];
        self.headArray = [NSMutableArray new];
        self.heightArray = [NSMutableArray new];
        self.saveArray = [NSMutableArray new];
        self.HSatisDetailArray = [NSMutableArray new];
        self.paramDic = paramDic;
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.myTableView];
    [self getTypeData];
    [self KeyBord];
    self.model = [[Model_Hr_SatType alloc]init];
    self.satis_Model = [[Model_Hr_Satisfaction alloc]init];
    
    
    UIBarButtonItem *NewButton = [[UIBarButtonItem alloc] initWithTitle:@"保存"
                                                                  style:UIBarButtonItemStylePlain
                                                                 target:self
                                                                 action:@selector(didSaveButttonClicked:)];
    self.navigationItem.rightBarButtonItem = NewButton;

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(contentTextViewDidediting:) name:UITextViewTextDidChangeNotification object:nil];
}

- (void)getTypeData
{
    InitDbTable *initDb = [[InitDbTable alloc]init];
    self.dataArray = [initDb GetHSatisfcationCodeWithCodeID:self.Type_id];
    for (int i = 0; i < self.dataArray.count; i ++) {
        Model_Hr_SatCode *model = self.dataArray[i];
        if ([model.LEVELS isEqualToString:@"1"]) {
            [self.titleArray addObject:model];
        }
    }
    
//创建三个数组,分别存表格上 中 下的数据
    
    NSMutableArray *UpBoxArray = [NSMutableArray new];
    NSMutableArray *inBoxArray = [NSMutableArray new];
    NSMutableArray *DownBoxArray = [NSMutableArray new];
    
    
    for (int i = 0; i < self.titleArray.count ; i ++) {
        Model_Hr_SatCode *model = self.titleArray[i];
        if ([model.CODE_POSTION isEqualToString:@"2"]) {
            [UpBoxArray addObject:model];
        }
        if ([model.CODE_POSTION isEqualToString:@"1"]) {
            [inBoxArray addObject:model];
        }
        if ([model.CODE_POSTION isEqualToString:@"3"]) {
            [DownBoxArray addObject:model];
        }
    }
     [UpBoxArray addObjectsFromArray:inBoxArray];
    [UpBoxArray addObjectsFromArray:DownBoxArray];
    
    self.titleArray = UpBoxArray;
    
     for (int i = 0;  i< self.titleArray.count; i ++) {
         
        Model_Hr_SatCode *model = self.titleArray[i];

         
         NSMutableArray * VAL_RANGEArray = (NSMutableArray *)[model.VAL_RANGE componentsSeparatedByString:@"/"];
         
//         if (VAL_RANGEArray.count >= 1) {
//             
//             [VAL_RANGEArray removeObjectAtIndex:0];
//         }
         
         NSMutableArray *valArray = [NSMutableArray new];
         
         for (int j = 0; j < VAL_RANGEArray.count; j ++) {
             
             NSString *value = VAL_RANGEArray[j];
             
             NSRange range = [value rangeOfString:@"~t"];
             
             NSString * result = [value substringToIndex:range.location];
             
             [valArray addObject:result];
         }

         model.array = (NSArray *)valArray;
         
        NSMutableArray *array  = [initDb GetHSatisfcationCodeWithParid:model.CODE_ID typeid:self.Type_id];
        
        if (array.count >= 1) {
            
            for (int j = 0; j < array.count; j ++) {
                
                Model_Hr_SatCode *MidModel = array[j];
                
                BigModel *bigModel = [[BigModel alloc]init];
                
                bigModel.array = MidModel.array;
                
                Model_Hr_Satisfaction *HSatisModel = [[Model_Hr_Satisfaction alloc]init];
                
                HSatisModel.SAT_DES = @"";
                
                if ([model.SCORE_METHOD isEqualToString:@"1"]) {
                    
                    NSMutableArray *itemArray = [initDb GetHSatisfcationItemWithGroupid:model.GROUP_ID];
                    
                    bigModel.smallArray = (NSArray *)itemArray;
                }
                if (j == 0) {
                    
                    bigModel.codeModel = model;
                    
                    bigModel.hasCodeModel = YES;
                }
                bigModel.midModel = MidModel;
                CGFloat height = [SizeToFit getHeightByWidth:ScreenWidth - 20 title:bigModel.midModel.CODE_NAME font:[UIFont systemFontOfSize:19]];
                bigModel.height = height;
                [self.headArray addObject:bigModel];
                
                [self.HSatisDetailArray addObject:HSatisModel];
            }
        }else {
            BigModel *bigModel = [[BigModel alloc]init];
            Model_Hr_Satisfaction *HSatisModel = [[Model_Hr_Satisfaction alloc]init];
            HSatisModel.SAT_DES = @"";
            if ([model.SCORE_METHOD isEqualToString:@"1"]) {
                NSMutableArray *itemArray = [initDb GetHSatisfcationItemWithGroupid:model.GROUP_ID];
                bigModel.smallArray = (NSArray *)itemArray;
            }
            bigModel.codeModel = model;
            bigModel.hasCodeModel = YES;
            CGFloat height = [SizeToFit getHeightByWidth:ScreenWidth - 20 title:bigModel.codeModel.CODE_NAME font:[UIFont systemFontOfSize:19]];
            bigModel.height = height;

            [self.headArray addObject:bigModel];
            [self.HSatisDetailArray addObject:HSatisModel];
        }
        [self.DetailArray addObject:array];
    }
    
    [self.myTableView reloadData];
}


- (UITableView *)myTableView
{
    if (!_myTableView) {
        _myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, NavBarHeight, ScreenWidth , ScreenHeight - NavBarHeight) style: UITableViewStyleGrouped];
        _myTableView.dataSource = self;
        _myTableView.delegate = self;
        _myTableView.backgroundColor = [UIColor whiteColor];
        _myTableView.tableFooterView = [[UIView alloc]init];
        _myTableView.separatorStyle = UITableViewCellSelectionStyleNone;
        [_myTableView registerClass:[HSatisDetailTableViewCell class] forCellReuseIdentifier:@"cell"];
    }
    return _myTableView;
}

- (UILabel *)dateTimeLabel
{
    if (!_dateTimeLabel) {
        _dateTimeLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 50, 100, 30)];
        _dateTimeLabel.text = @"检查时间:";
        _dateTimeLabel.font = [UIFont systemFontOfSize:15];
        
    }
    return _dateTimeLabel;
}
- (UIButton *)dateTimeButton
{
    if (!_dateTimeButton) {
        _dateTimeButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _dateTimeButton.frame = CGRectMake(self.dateTimeLabel.right + 10, 50,ScreenWidth - self.dateTimeLabel.right - 20, 30);
        _dateTimeButton.backgroundColor = [UIColor whiteColor];
        _dateTimeButton.layer.borderColor = [RGB(212,212,212) CGColor];
        _dateTimeButton.layer.borderWidth = 0.3f;
        _dateTimeButton.layer.masksToBounds = YES;
        _dateTimeButton.layer.cornerRadius = 5;
        [_dateTimeButton setTitle:[super getNowDate] forState:UIControlStateNormal];
        _dateTimeButton.titleLabel.textAlignment = NSTextAlignmentLeft;
        [_dateTimeButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _dateTimeButton.titleLabel.font = [UIFont systemFontOfSize:16];
        [_dateTimeButton addTarget:self action:@selector(timeDate:) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return _dateTimeButton;
}



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.headArray.count;
}
#pragma mark  委托  UITableView


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    BigModel *model = self.headArray[section];
    if (model.smallArray.count == 0) {
        return 1;
    }else {
        return model.smallArray.count;
    }
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *headView = [[UIView alloc]init];
    
//    headView.backgroundColor = [UIColor redColor];
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, ScreenWidth -20, 30)];
    
//    label.backgroundColor = [UIColor orangeColor];
    
    BigModel *model = self.headArray[section];
    
    if (model.hasCodeModel == YES) {
        
        if ([model.midModel.NOTNULL_FALG isEqualToString:@"1"]) {

            label.text = [NSString stringWithFormat:@" %@\n* %@",model.codeModel.CODE_NAME,model.midModel.CODE_NAME?:@""];
            
        }else if (model.midModel.NOTNULL_FALG == nil && [model.codeModel.NOTNULL_FALG isEqualToString:@"1"] ){
            
            label.text = [NSString stringWithFormat:@" * %@\n %@",model.codeModel.CODE_NAME,model.midModel.CODE_NAME?:@""];

        }else {
            
            label.text = [NSString stringWithFormat:@" %@\n%@",model.codeModel.CODE_NAME,model.midModel.CODE_NAME?:@""];
        }


    }else {
        
        if ([model.midModel.NOTNULL_FALG isEqualToString:@"1"]) {
            
            label.text = [NSString stringWithFormat:@"* %@",model.midModel.CODE_NAME];

        }else {
            
            label.text = [NSString stringWithFormat:@"%@",model.midModel.CODE_NAME];

        }
    }
    CGFloat height = [SizeToFit getHeightByWidth:ScreenWidth - 20 title:label.text font:[UIFont systemFontOfSize:19]];
    
    label.numberOfLines = 0;
    
    label.frame = CGRectMake(10, 0 ,ScreenWidth - 20, height);
    
    NSRange range = [label.text rangeOfString:@"*"];

    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:label.text];
    
    [str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:range];

    label.attributedText = str;
    
//    model.height = height;
    
//    [self.myTableView reloadData];

    [headView addSubview:label];
    
    
    if (section == 0) {
        
        UILabel *deptLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 100, 30)];
        deptLabel.text = @"病区";
        deptLabel.font = [UIFont systemFontOfSize:16];
        self.deptButton = [UIButton buttonWithType:UIButtonTypeCustom];
        self.deptButton.frame = CGRectMake(deptLabel.right + 10, 10, ScreenWidth - deptLabel.right - 20, 30);
        [self.deptButton setTitle:self.satis_Model.dept_name?:@"请选择科室" forState:UIControlStateNormal];
        self.deptButton.titleLabel.font = [UIFont systemFontOfSize:16];
        [self.deptButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        self.deptButton.layer.borderColor = [RGB(212,212,212) CGColor];
        self.deptButton.layer.borderWidth = 0.3f;
        self.deptButton.layer.masksToBounds = YES;
        self.deptButton.layer.cornerRadius = 5;
        [self.deptButton addTarget:self action:@selector(chooseDepart:) forControlEvents:UIControlEventTouchUpInside];

        
        label.top = self.dateTimeButton.bottom + 10;
        [headView addSubview:deptLabel];
        [headView addSubview:self.deptButton];
        [headView addSubview:self.dateTimeLabel];
        [headView addSubview:self.dateTimeButton];
        
    }
    return headView;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    HSatisDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    BigModel *model = self.headArray[indexPath.section];
    NSArray *array = model.smallArray;
    Model_Hr_SatCodeItem *iteModel = [[Model_Hr_SatCodeItem alloc]init];
     BOOL hasItem = NO;
    if (array.count > 0) {
        hasItem = YES;
        iteModel = array[indexPath.row];
    }else {
        hasItem = NO;
        
    }
    
    [cell cellWithData:iteModel hasItemArray:hasItem cell:cell headArray:self.headArray indexSection:indexPath.section score_method:model.codeModel.SCORE_METHOD];
    if ([model.codeModel.SCORE_METHOD isEqualToString:@"4"]) {
        self.indexSection = indexPath.section;
    }
    [cell.dateButton addTarget:self action:@selector(dateTime:) forControlEvents:UIControlEventTouchUpInside];
    [cell.chooseButton addTarget:self action:@selector(choose:) forControlEvents:UIControlEventTouchUpInside];
    cell.chooseButton.tag = 100 + indexPath.section;
    [cell.dateButton setTitle:self.satis_Model.MODIFY_DATE?:@"" forState:UIControlStateNormal];
    cell.ItemLabel.text = iteModel.ITEM_NAME;
    cell.textview.tag = indexPath.section;
    self.chooseSection = indexPath.section;
    [cell.chooseButton setTitle:model.InformationText forState:UIControlStateNormal];
    cell.textview.text = model.InformationText?:@"";
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSInteger section = indexPath.section;
    BigModel *model = self.headArray[indexPath.section];
    NSArray *array = model.smallArray;
    Model_Hr_SatCodeItem *iteModel = array[indexPath.row];
    Model_Hr_Satisfaction *hsModel = self.HSatisDetailArray[section];
    if ([iteModel.ITEM_ID isEqualToString:@"null"]||[iteModel.ITEM_ID isEqual:[NSNull null]]) {
        iteModel.ITEM_ID = @"";
    }
    hsModel.ITEM_ID = iteModel.ITEM_ID?:@"";
    for (Model_Hr_SatCodeItem *smallModel in model.smallArray) {
        smallModel.isSelected = NO;
    }
    hsModel.ITEM_SCORE = [iteModel.VALUE doubleValue];
    iteModel.isSelected = !iteModel.isSelected;
    [self.myTableView reloadData];
}


- (void)contentTextViewDidediting:(NSNotification *)noti
{
    UITextView *textView = noti.object;
    BigModel *model = self.headArray[textView.tag];
    Model_Hr_Satisfaction *HSatisModel = self.HSatisDetailArray[textView.tag];
    if (model.smallArray.count == 0) {
        HSatisModel.ITEM_SCORE = -1;
        HSatisModel.SAT_DES = textView.text?:@" ";
    }
    model.InformationText = textView.text?:@" ";
    self.satis_Model.REASONS = textView.text?:@" ";
    
}
- (CGFloat )tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return CGFLOAT_MIN;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    NSIndexPath *indexPath = [[NSIndexPath alloc]initWithIndex:section];
    BigModel *model = self.headArray[section];
    if (indexPath.section == 0) {
        return model.height + 80;
    }else {
        return model.height + 10;
    }
}


- (MPickerSelectionView *)pickerSelectionView {
    if (!_pickerSelectionView) {
        _pickerSelectionView = [[MPickerSelectionView alloc]init];
        _pickerSelectionView.delegate = self;
        
    }
    return _pickerSelectionView;
}
- (UIDatePicker *)datePicker {
    if (!_datePicker) {
        _datePicker = [[UIDatePicker alloc]init];
        _datePicker.backgroundColor = [UIColor whiteColor];
        _datePicker.datePickerMode = UIDatePickerModeDateAndTime;
        _datePicker.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];
    }
    return _datePicker;
}
- (void)timeDate:(UIButton *)sender
{
    self.dateFlag = 1;
    [self.pickerSelectionView present];
    
}
- (void)dateTime:(UIButton *)sender
{
    self.dateFlag = 2;
    [self.pickerSelectionView present];
}

- (void)choose:(UIButton *)sender
{
    HQPickerView *picker = [[HQPickerView alloc]initWithFrame:self.view.bounds];
    
    picker.delegate = self ;
    
    BigModel*model = self.titleArray[sender.tag - 100];
    
    self.chooseSection = sender.tag - 100;
    
    picker.customArr = model.array;
        
    [self.view addSubview:picker];
}
- (UIView *)viewWithMPickerSelectionView:(MPickerSelectionView *)pickerSelectionView {
    return self.datePicker;
}

- (void)confirmEventWithMPickerSelectionView:(MPickerSelectionView *)pickerSelectionView
{
    if (self.dateFlag == 1) {
        NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
        [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm"];
        NSString *dateString = [dateFormat stringFromDate:self.datePicker.date];
        [self.dateTimeButton setTitle:dateString forState:UIControlStateNormal];
        self.satis_Model.SURVEY_DATE = dateString;
    }else {
        Model_Hr_Satisfaction *HSatisModel = self.HSatisDetailArray[self.indexSection];
        NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
        [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm"];
        NSString *dateString = [dateFormat stringFromDate:self.datePicker.date];
        self.satis_Model.MODIFY_DATE = dateString;
        HSatisModel.SAT_DES = dateString?:@"";
        HSatisModel.ITEM_SCORE = -1;
        [self.myTableView reloadData];
    }
}

- (void)chooseDepart:(UIButton *)sender
{
    HQCDepartViewController *HQCDVC = [[HQCDepartViewController alloc]initWithType:5 modelArray:nil standard_id:self.Type_id];
    UINavigationController *navHQCDVC = [[UINavigationController alloc]initWithRootViewController:HQCDVC];
    HQCDVC.title = @"选择";
    HQCDVC.getBlocks_codeItem = ^(NSString *dept_name , NSString *dept_id) {
        [self.deptButton setTitle:dept_name forState:UIControlStateNormal];
        self.satis_Model.dept_name = dept_name;
        self.satis_Model.DEPT_CODE = dept_id;
        [self.myTableView reloadData];
        
    };
    [self presentViewController:navHQCDVC animated:YES completion:NULL];
}

- (void)didSaveButttonClicked:(UIButton *)sender
{

    for (int i = 0; i < self.HSatisDetailArray.count; i ++) {
        
        BigModel *bigModel = self.headArray[i];
        Model_Hr_Satisfaction *model = self.HSatisDetailArray[i];
        model.SURVEY_DATE = self.dateTimeButton.titleLabel.text?:@"";
        model.STATUS = 1;
        model.DEPT_CODE = self.satis_Model.DEPT_CODE?:@"";
        model.MODIFIER = [UserDefault getUserInfo].USER_NAME?:@"";
        model.MODIFY_ID = [UserDefault getUserInfo].USER_ID;
        model.MODIFY_DATE = self.dateTimeButton.titleLabel.text?:@"";
        model.TABLE_CODE = [super createPrimaryID]?:@"";
        model.SAT_ID = self.Type_id;
        model.SAT_TYPE = self.Type_id;
        model.DELETE_FLAG = 0;
        model.STEP_ID = [self.paramDic objectForKey:@"STEP_ID"];
        model.SAT_PERIOD = @"";
        model.ORG_ID = @"";
        model.REASONS = @"";
        model.UPLOAD_FLAG = 0;
        model.SAT_DES2 = @"";
        model.TEMP_COL = @"";

//        if (bigModel.hasCodeModel == YES) {
        model.ITEM_CODE = bigModel.midModel.CODE_ID?:bigModel.codeModel.CODE_ID;
        if ([bigModel.midModel.NOTNULL_FALG isEqualToString:@"1"] && model.ITEM_ID == nil) {
            [HCommon popupErrorMessage:@"有必填项未填,请确认!"];
            return;
        }
        if (bigModel.midModel.NOTNULL_FALG == nil && [bigModel.codeModel.NOTNULL_FALG isEqualToString:@"1"] && model.ITEM_ID == nil) {
            [HCommon popupErrorMessage:@"有必填项未填,请确认!"];
            return;

        }
        if (self.satis_Model.dept_name.length == 0) {
            
            [HCommon popupErrorMessage:@"请选择科室"];
            return;
        }
        
        if (bigModel.smallArray.count == 0) {
            model.ITEM_CODE = bigModel.codeModel.CODE_ID;
        }
    }
    
    [[HSatisSave alloc]initWithFormData:self.HSatisDetailArray];
    [HCommon popupSuccessMessage:@"保存成功"];
    [self.navigationController popViewControllerAnimated:YES];
    
}

#pragma mark 监听键盘,回收
- (void)KeyBord
{
    //点击空白处回收键盘
    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(keyboardHide:)];
    //设置成NO表示当前控件响应后会传播到其他控件上，默认为YES。
    tapGestureRecognizer.cancelsTouchesInView = NO;
    //将触摸事件添加到当前view
    [self.view addGestureRecognizer:tapGestureRecognizer];
    
    //添加观察者 当键盘弹出时，tableview随之上移,不会遮挡
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}

//这一句不能去掉  否则点击屏幕的任何一个地方都会崩溃
- (void)keyboardHide:(UITapGestureRecognizer *)tap {
    [self.view endEditing:YES];
}
#pragma mark 键盘出现
-(void)keyboardWillShow:(NSNotification *)note
{
    CGRect keyBoardRect=[note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    self.myTableView.contentInset = UIEdgeInsetsMake(0, 0, keyBoardRect.size.height, 0);
}
#pragma mark 键盘消失
-(void)keyboardWillHide:(NSNotification *)note
{
    self.myTableView.contentInset = UIEdgeInsetsZero;
}

- (void)pickerView:(UIPickerView *)pickerView didSelectText:(NSString *)text indexRow:(NSInteger)indexRow tags:(NSInteger)tags{
    
    BigModel *model = self.headArray[self.chooseSection];
    Model_Hr_Satisfaction *HSatisModel = self.HSatisDetailArray[self.chooseSection];
    if (model.smallArray.count == 0) {
        HSatisModel.ITEM_SCORE = -1;
        HSatisModel.SAT_DES = text?:@" ";
    }
    model.InformationText = text?:@" ";
    self.satis_Model.REASONS = text?:@" ";
    
    [self.myTableView reloadData];

}

//- (void)viewDidAppear:(BOOL)animated
//{
//    [self.myTableView reloadData];
//}
- (void)didReceiveMemoryWarning {
    
    [super didReceiveMemoryWarning];
}



@end
